package com.kevin.elasticjob.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
import com.google.common.collect.Lists;
import com.kevin.elasticjobboot.Job;

import java.util.Collections;
import java.util.List;

/**
 * @author Kevin Liu
 * @date 2020/7/30 下午4:11
 */
@Job(jobName = "myDataFlowJob")
public class MyDataFlowJob implements DataflowJob<String> {

    private static int count = 0;


    @Override
    public List<String> fetchData(ShardingContext shardingContext) {
        int maxSize = 10;
        if (count < maxSize) {
            count++;
            return Lists.newArrayList("kevin", "love", "you");
        }
        return Collections.emptyList();
    }

    @Override
    public void processData(ShardingContext shardingContext, List<String> list) {
        list.forEach(System.out::println);
    }
}
